<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class get_value extends CI_Controller {

    public function __construct() {
        $this->_ci = &get_instance();
        $this->_ci->load->model('general_model');
    }

    function get_pat_status($pat_id) {
        $row = $this->_ci->general_model->get_row_select('*', 'check_pat', "pat_id = {$pat_id} order by check_id DESC limit 1", '');
        if ($row == false) {
            return "<label  class='label label-warning'>ยังไม่ได้รับการตรวจ</label>";
        } elseif ($row['doc_id_after'] != '' && $row['doc_id_after'] != '0000-00-00 00:00:00') {
            return "<label  class='label label-success'>ตรวจหลังทำสวยงามแล้ว</label>";
        } elseif ($row['doc_id_before'] != '' && $row['doc_id_before'] != '0000-00-00 00:00:00') {
            return "<label  class='label label-inverse'>รอตรวจหลังทำสวยงาม</label>";
        } elseif ($row['check_date'] != '' && $row['check_date'] != '0000-00-00 00:00:00') {
            return "<label  class='label label-info'>รอตรวจก่อนทำสวยงาม</label>";
        }
    }

    function get_pat_status2($pat_id) {
        $row = $this->_ci->general_model->get_row_select('check_status', 'check_pat', "pat_id = {$pat_id} order by check_id DESC limit 1", '');
        if ($row == false) {
            return "<label  class='label label-warning'>ยังไม่ได้รับการตรวจ</label>";
        } else {
            return "<label  class='label label-success'>" . $row['check_status'] . "</label>";
        }
    }

    function get_pat_status3($pat_id) {
        $row = $this->_ci->general_model->get_row_select('check_status', 'check_pat', "pat_id = {$pat_id} order by check_id DESC limit 1", '');

        if ($row == false) {
            return "ยังไม่ได้รับการตรวจ";
        } else {
            return $row['check_status'];
        }
    }

    function get_tools_by_check_id($check_id) {
        $row = $this->_ci->general_model->get_all('order_tools', "check_id = {$check_id}", "");
        return $row;
    }

    function get_tools_id($tool_id) {
        $row = $this->_ci->general_model->get_row_select('tool_name', 'tools', "tool_id = {$tool_id}", "");
        return $row['tool_name'];
    }

    function get_tools_type($tool_id) {
        $row = $this->_ci->general_model->get_row_select('tool_type', 'tools', "tool_id = {$tool_id}", "");
        return $row['tool_type'];
    }

    function get_tools_name($tool_id) {
        $row = $this->_ci->general_model->get_row_select('tool_name', 'tools', "tool_id = {$tool_id}", "");
        return $row['tool_name'];
    }

    function get_doctor_name($user_id) {
        $row = $this->_ci->general_model->get_row_select('doc_prename,doc_name,doc_lname', 'doctors', "user_id = {$user_id}");
        return $row['doc_prename'] . $row['doc_name'] . '    ' . $row['doc_lname'];
    }

    function get_tech_name($user_id) {
        $row = $this->_ci->general_model->get_row_select('tech_prename,tech_name,tech_lname', 'techs', "user_id = {$user_id}");
        return $row['tech_prename'] . $row['tech_name'] . '    ' . $row['tech_lname'];
    }

    function get_staff_name($user_id) {
        $row = $this->_ci->general_model->get_row_select('sf_prename,sf_name,sf_lname', 'staffs', "user_id = {$user_id}");
        return $row['sf_prename'] . $row['sf_name'] . '    ' . $row['sf_lname'];
    }

}

######################################

function get_tool_status($order_id) {
     if($order_id == false)
    {
        return 'ข้อมูลไม่ถูกต้อง';
        die();
    }
    $CI = &get_instance();
    $CI->load->model('general_model');
    $row = $CI->general_model->get_row_select('order_status', 'order_tools', "order_id = {$order_id}", "");
    return $row['order_status'];
}
 function _doctor_name($user_id) {
     if($user_id == false)
    {
        return 'ข้อมูลไม่ถูกต้อง';
        die();
    }
        $CI = &get_instance();
        $CI->load->model('general_model');
        $row = $CI->general_model->get_row_select('doc_prename,doc_name,doc_lname', 'doctors', "user_id = {$user_id}");
        if(!empty($row))
        {
             return $row['doc_prename'] . $row['doc_name'] . '    ' . $row['doc_lname'];
        }else
        {
            return '-';
        }
    }
    function _tech_name($user_id) {
        if($user_id == false)
    {
        return 'ข้อมูลไม่ถูกต้อง';
        die();
    }
        $CI = &get_instance();
        $CI->load->model('general_model');
        $row = $CI->general_model->get_row_select('tech_prename,tech_name,tech_lname', 'techs', "user_id = {$user_id}");
        return $row['tech_prename'] . $row['tech_name'] . '    ' . $row['tech_lname'];
    }

function _get_techFromCheckId($check_id) {
    if($check_id == false)
    {
        return 'ข้อมูลไม่ถูกต้อง';
        die();
    }
    $CI = &get_instance();
    $CI->load->model('general_model');
    $row = $CI->general_model->get_row_select('tech_id', 'order_tools', "check_id = {$check_id}", "");
    if (!empty($row['tech_id'])) {
        $row2 = $CI->general_model->get_row_select('tech_prename,tech_name,tech_lname', 'techs', "user_id = {$row['tech_id']}");
        return $row2['tech_prename'] . $row2['tech_name'] . '    ' . $row2['tech_lname'];
    } else {
        return " - ";
    }
}
function _get_AmpTypeName($amp_type_id) {
    if($amp_type_id == false)
    {
        return 'ข้อมูลไม่ถูกต้อง';
        die();
    }
    $CI = &get_instance();
    $CI->load->model('general_model');
    $row = $CI->general_model->get_row_select('amp_type_name', 'amp_types', "amp_type_id = {$amp_type_id}", "");
    if (!empty($row['amp_type_name'])) 
    {
        return $row['amp_type_name'];
    } else {
        return " - ";
    }
}
function _get_statusFromCheckId($check_id) {
    $CI = &get_instance();
    $CI->load->model('general_model');
    $row = $CI->general_model->get_row_select('tech_id', 'order_tools', "check_id = {$check_id}", "");
    if (!empty($row['tech_id'])) {
        $row2 = $CI->general_model->get_row_select('tech_prename,tech_name,tech_lname', 'techs', "user_id = {$row['tech_id']}");
        return $row2['tech_prename'] . $row2['tech_name'] . '    ' . $row2['tech_lname'];
    } else {
        return " - ";
    }
}



function _set_date_full($date = false) {
        if ($date != '0000-00-00' and $date != FALSE) {
            $strYear = date("Y", strtotime($date)) + 543;
            $strMonth = date("n", strtotime($date));
            $strDay = date("j", strtotime($date));
            $strMonthCut = Array("", "มกราคม", "กุมภาพันธ์", "มีนาคม", "เมษายน.", "พฤษภาคม", "มิถุนายน", "กรกฎาคม", "สิงหาคม", "กันยายน", "ตุลาคม.", "พฤศจิกายน", "ธันวาคม");
            $strMonthThai = $strMonthCut[$strMonth];
            return "$strDay $strMonthThai $strYear";
        } else {
            return " - ";
        }
    }

       function _set_date($date = false) {

        if ($date != '0000-00-00' and $date != FALSE) {
            $strYear = date("Y", strtotime($date)) + 543;
            $strMonth = date("n", strtotime($date));
            $strDay = date("j", strtotime($date));
            $strMonthCut = Array("", "ม.ค.", "ก.พ.", "มี.ค.", "เม.ย.", "พ.ค.", "มิ.ย.", "ก.ค.", "ส.ค.", "ก.ย.", "ต.ค.", "พ.ย.", "ธ.ค.");
            $strMonthThai = $strMonthCut[$strMonth];
            return "$strDay $strMonthThai $strYear";
        } else {
            return " - ";
        }
    }